package com.lsongh.springboot2.controller;

import com.lsongh.springboot2.entity.Exam;
import com.lsongh.springboot2.entity.Result;
import com.lsongh.springboot2.service.CheckService;
import com.lsongh.springboot2.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CheckController {

    @Autowired
    CheckService checkService;

    @GetMapping("check/findAll")
    public Result<Exam> findChecks(@RequestParam("modelType") String modelType, @RequestParam("name") String name){
        if(name==""){
            List<Exam> list = checkService.findChecks(modelType);
            return ResultUtil.success(list);
        }else {
            List<Exam> list = checkService.findChecksByName(modelType,name);
            return ResultUtil.success(list);
        }

    }

    @PutMapping("check/type/{id}")
    public Result<String> updateType(@PathVariable("id") int id,@RequestParam("type") Integer type){
        checkService.updateCheckType(type,id);
        return ResultUtil.success("审核状态已更新");
    }


    @GetMapping("check/list")
    public List<Exam> findAll(){
        return checkService.findAll();
    }

}
